<template>
    <div class="content_panel project_modules">
        <div class="content_panel_top">
            <h3 class="panel_title">
                <span>{{ $t('salesManage.roborOrderManage') }}</span>
            </h3>
        </div>
        <div class="module_content">
            <h4>
                <span>{{ $t('salesManage.botSplitUserType') }}</span>
            </h4>
            <div class="check-broup">
                <el-checkbox-group v-model="checkList">
                    <el-checkbox  label="whiteListStatus" :disabled="isDisable">{{ $t('salesManage.whitUserList') }}</el-checkbox>
                    <el-checkbox label="unReLoanStatus" :disabled="isDisable">{{ $t('salesManage.repaynotloanUser') }}</el-checkbox>
                    <el-checkbox label="loanFourDaysStatus" :disabled="isDisable">{{ $t('salesManage.firstPay4Days') }}</el-checkbox>
                </el-checkbox-group>
            </div>
            <div class="submint">
                <el-button @click="edit"  type="primary" v-if="isDisable">{{ $t('common.edit') }}</el-button>
                <el-button @click="submint"  type="primary" v-else>{{ $t('common.confirmOk') }}</el-button>

            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            checkList: [],
            checkBoxList:[],
            isDisable:true
        }
    },
    methods:{
        queryAssignConfig(){
            this.$api.telSales.queryAssignConfig().then(res => {
                const { status, data, error } = res;
                if ('1' === status && '00000000' === error && data) {
                    for (let key in data) {
                        this.checkBoxList.push(key)
                        if (data[key] === 1) {
                            this.checkList.push(key)
                        }
                    };
                };
            });
        },
        edit(){
            this.isDisable = false
        },
        submint(){
            let params = {};
            this.checkBoxList.forEach(item=>{
                console.warn(item,this.checkList.indexOf(item))
                params[item]=this.checkList.indexOf(item)==-1?0:1
            });
            this.$api.telSales.updateAssignConfig(params).then(res => {
                const { status, error ,msg} = res;
                if ('1' === status && '00000000' === error) {
                    this.isDisable=true
                }else{
                    this.$message.error(msg);
                }
            });
        }
    },
    created(){
        this.queryAssignConfig()
    }
}
</script>
<style lang="scss">
    .check-broup{
        padding: 20px 0;
    }
    .content_panel_top{
        padding-bottom:10px;
    }
</style>